<?php

/**
 * Alquiler filter form base class.
 *
 * @package    blackDrums
 * @subpackage filter
 * @author     Your name here
 */
abstract class BaseAlquilerFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'horaInicio'        => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'horaFin'           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'direccion'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'fecha'             => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'idClienteNatural'  => new sfWidgetFormPropelChoice(array('model' => 'ClienteNatural', 'add_empty' => true)),
      'idClienteJuridico' => new sfWidgetFormPropelChoice(array('model' => 'ClienteJuridico', 'add_empty' => true)),
      'idEvento'          => new sfWidgetFormPropelChoice(array('model' => 'Evento', 'add_empty' => true)),
      'detalle_list'      => new sfWidgetFormPropelChoice(array('model' => 'Equipo', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'horaInicio'        => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'horaFin'           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'direccion'         => new sfValidatorPass(array('required' => false)),
      'fecha'             => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'idClienteNatural'  => new sfValidatorPropelChoice(array('required' => false, 'model' => 'ClienteNatural', 'column' => 'cedula')),
      'idClienteJuridico' => new sfValidatorPropelChoice(array('required' => false, 'model' => 'ClienteJuridico', 'column' => 'rif')),
      'idEvento'          => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Evento', 'column' => 'idEvento')),
      'detalle_list'      => new sfValidatorPropelChoice(array('model' => 'Equipo', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('alquiler_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addDetalleListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(DetallePeer::IDALQUILER, AlquilerPeer::IDALQUILER);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(DetallePeer::IDEQUIPO, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(DetallePeer::IDEQUIPO, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Alquiler';
  }

  public function getFields()
  {
    return array(
      'idAlquiler'        => 'Number',
      'horaInicio'        => 'Date',
      'horaFin'           => 'Date',
      'direccion'         => 'Text',
      'fecha'             => 'Date',
      'idClienteNatural'  => 'ForeignKey',
      'idClienteJuridico' => 'ForeignKey',
      'idEvento'          => 'ForeignKey',
      'detalle_list'      => 'ManyKey',
    );
  }
}
